package com.smart.member.common.utils;

import java.util.Random;

public class MemberUtils {
    /**
     * 邮箱正则
     */
    public static final String CONSTANT_REGEXP_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
    /**
     * 手机号正则
     */
    public static final String CONSTANT_REGEXP_PHONE = "^[1][3-9]\\d{9}$";
    /**
     * 密码正则
     */

    public static final String CONSTANT_REGEXP_PASSWORD = "^[a-z]\\w{17}$";
    /**
     * 字符串常量
     */
    private static final String CONSTANT_NAME_STR = "char";
    /**
     * 数字常量
     */
    private static final String CONSTANT_NAME_NUM = "num";

    /**
     * 生成随机用户名，数字和字母组成,
     *
     * @param length
     * @return
     */
    public static String getStringRandom(int length) {
        StringBuilder username = new StringBuilder();
        Random random = new Random();
        //参数length，表示生成几位随机数
        for (int i = 0; i < length; i++) {

            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
            //输出字母还是数字
            if (CONSTANT_NAME_STR.equalsIgnoreCase(charOrNum)) {
                //输出是大写字母还是小写字母
                int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
                username.append((char) (random.nextInt(26) + temp));
            } else {
                username.append(String.valueOf(random.nextInt(10)));
            }
        }
        return username.toString();
    }
}
